package com.arceus.leetcode;

import java.util.LinkedHashMap;

/**
 * @author : iron
 * @version : 1.0.0
 * @date : 2:26 PM 2018/12/24
 */

public class T387 {

    public static void main(String[] args) {
        String s = "wwawdadasdat";
        System.out.println(firstUniqChar(s));
    }

    public static int firstUniqChar(String s) {
        LinkedHashMap<Character, Integer> linkedHashMap = new LinkedHashMap<Character, Integer>();
        char[] a = s.toCharArray();

        for (char c : a) {
            if (linkedHashMap.containsKey(c)) {
                linkedHashMap.put(c, linkedHashMap.get(c) + 1);
            } else {
                linkedHashMap.put(c, 1);
            }
        }

        int i = -1;

        for (char c : a) {
            i++;
            if (linkedHashMap.get(c)==1){
                return i;
            }
        }
        return -1;
    }
}
